package com.quik.web.front.mapper;

import org.springframework.stereotype.Repository;

import com.quik.backend.mapper.BaseDao;
import com.quik.entity.BookingRoom;
import com.quik.entity.DtaProduct;
import com.quik.entity.Room;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

/**
 * 功能说明：
 *        咨客-房间持久化层
 * @author jenny
 *
 */
@Repository
public class ConsultRoomDao extends BaseDao<Object> {
	/**
	 * 查询房间类型列表
	 * @return
	 * @throws Exception
	 */
	public List findRoomTypeList() throws Exception{
		List list = loadAll("findRoomTypeList");
		return list;
	}
	
	/**
	 * 查询房间区域列表
	 * @return
	 * @throws Exception
	 */
	public List findRoomAreaList() throws Exception{
		List list = loadAll("findRoomAreaList");
		return list;
	}
	
	/**
	 * 根据条件查询房间列表
	 * @param roomType 房间类型ID
	 * @param roomArea  房间区域ID
	 * @param status  房间状态
	 * @return
	 * @throws Exception
	 */
	public List findRoomList(Integer roomType, Integer roomArea, String status, String section) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>(4);
		map.put("roomType", roomType);
		map.put("roomArea", roomArea);
		map.put("status", status);
		map.put("section", section);
		
		List roomList = load("findRoomList", map);
		return roomList;
	}
	
	/**
	 * 按房间类型、状态查询房间数量
	 * @return
	 * @throws Exception
	 */
	public List findRoomStatList(String section) throws Exception{
		List list = load("findRoomStatList", section);
		return list;
	}
	
	/**
	 * 根据房间ID查询房间
	 * @param roomId
	 * @return
	 * @throws Exception
	 */
	public Room findRoomById(Integer roomId, String section) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>(2);
		map.put("roomId", roomId);
		map.put("section", section);
		
		Room room = (Room)get("findRoomById", map);
		return room;
	}
	
	/**
	 * 根据房间ID查询房间绑定的商品信息
	 * @param roomId
	 * @return
	 * @throws Exception
	 */
	public DtaProduct findProductByRoomId(Integer roomId) throws Exception{
		DtaProduct product = (DtaProduct)get("findProductByRoomId", roomId);
		return product;
	}
	
	/**
	 * 房间绑定的商品
	 * @param tokenNo
	 * @return
	 * @throws Exception
	 */
	public DtaProduct findRoomBoundProduct(String roomNo) throws Exception{
		DtaProduct product = (DtaProduct)get("findRoomBoundProduct", roomNo);
		return product;
	}
	
	/**
	 * 更新房间状态
	 * @param roomNo
	 * @param status
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateRoomStatus(String roomNo, String status, String staffNo) throws Exception{
		Map<String, String> map = new HashMap<String, String>(3);
		map.put("roomNo", roomNo.trim());
		map.put("status", status);
		map.put("staffNo", staffNo);
		
		this.update("updateRoomStatus", map);
	}
	
	/**
	 * 根据房间编号查询房间
	 * @param roomNo
	 * @return
	 * @throws Exception
	 */
	public Room findRoomByRoomNo(String roomNo) throws Exception{
		Room room = (Room)get("findRoomByRoomNo", roomNo.trim());
		return room;
	}
	
	/**
	 * 根据条件查询房间数量
	 * @param roomNo
	 * @param roomType
	 * @param roomArea
	 * @param status
	 * @return
	 * @throws Exception
	 */	
	public int findRoomCount(String roomNo, Integer roomType, Integer roomArea, String status) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roomNo", roomNo);
		map.put("roomType", roomType);
		map.put("roomArea", roomArea);
		map.put("status", status);
		
		Integer count = (Integer)get("consultant.findRoomCount", map);
		return count;
	}
	
	/**
	 * 根据条件查询房间列表（分页）
	 * @param roomNo
	 * @param roomType
	 * @param roomArea
	 * @param status
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public List findRoomList(String roomNo, Integer roomType, Integer roomArea, String status, Integer intPage, Integer pageSize) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roomNo", roomNo);
		map.put("roomType", (roomType == null || roomType == -1) ? null : roomType);
		map.put("roomArea", (roomArea == null || roomArea == -1) ? null : roomArea);
		map.put("status", status);
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = load("findRoomPageList", map);
		return list;
	}
	
	/**
	 * 查询房间预订的数量
	 * @param roomId
	 * @param bookingDate
	 * @return
	 * @throws Exception
	 */
	public int findBookingRoomCount(Integer roomId, String bookingDate) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roomId", roomId);
		map.put("bookingDate", bookingDate);
		
		Integer count = (Integer)get("findBookingRoomCount", map);
		return count;
	}
	
	/**
	 * 预订房间
	 * @param bookingRoom
	 * @throws Exception
	 */
	public void addBookingRoom(BookingRoom bookingRoom) throws Exception{
		add("addBookingRoom", bookingRoom);
	}
}
